package com.example.exploreactivedemo1.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import java.util.zip.Inflater

abstract class BaseFragment<VB : ViewBinding> : Fragment() {
    private var _binding : VB? = null

    /**
     * fragementBinding是指向的是每个子类
     */
    protected val fragementBinding : VB
        get() = _binding!!

    //设置一个可读可写属性
//    protected var fragementBinding1 : VB
//        get() = _binding!!
//        set(value) {
//            _binding = value
//        }

    //这个函数需要继承的各个子类函数
    abstract fun inflateBinding(inflater: LayoutInflater,container : ViewGroup?) : VB

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _binding = inflateBinding(inflater,container)
        //初始化view
        initView(_binding?.root)
        return _binding?.root
    }

    open fun initView(rootView : View?){

    }

//下面这个用不到了，现在通过viewBinding就已经获取到Fragment对应的View了，通过return _binding?.root就返回了其Fragment对应的View
    abstract fun getLayoutResId() : Int
}